package com.imooc.authorization.context;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2016/8/29.
 */
@Component
public class WebApplicationContext implements ApplicationContextAware{

    private static ApplicationContext ctx;

    private WebApplicationContext(){}

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ctx= applicationContext;
    }

    public static <T> T getBean(Class clazz){

        return (T)ctx.getBean(clazz);
    }
}
